<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8">
		<title>动态显示时间</title>
	</head>
	<body>
		<div id="clock"></div>
		<input id="btn1" type="button" value="暂停" onclick="stoptime()" />
		<input id="btn2" type="button" value="开始" onclick="starttime()" disabled="disabled" />
		<script type="text/javascript">
			var clock=document.getElementById("clock");
			var btn1=document.getElementById("btn1");	
			var btn2=document.getElementById("btn2");
			function showtime(){
				var d=new Date();
				var year=d.getFullYear();
				var month=d.getMonth()+1;
				var day=d.getDate();
				var h=d.getHours();
				var m=d.getMinutes();
				var s=d.getSeconds();
				clock.innerHTML="<h2>"+year+"-"+month+"-"+day+" "+h+":"+m+":"+s+"</h2>";
			}
			
			var tid=setInterval("showtime()",1000);
			
			function stoptime(){
				clearInterval(tid);
				btn2.disabled=false;
				btn1.disabled=true;
			}
			function starttime(){
				tid=setInterval("showtime()",1000);
				console.log(tid);
				btn1.disabled=false;
				btn2.disabled=true;
			}
		</script>
		
	</body>
</html>
